package com.zy.springboot.controller.book;

import com.alibaba.fastjson.JSONObject;
import com.zy.springboot.com.BaseUtils;
import com.zy.springboot.com.ResponseUtils;
import com.zy.springboot.com.SignUtil;
import com.zy.springboot.entity.user.UserEntity;
import com.zy.springboot.service.book.BookService;
import com.zy.springboot.service.book.RecordsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.net.URL;
import java.net.URLEncoder;

/**
 * Created by y on 2019/1/11.
 */
@Api(value = "阅读记录接口", description = "阅读记录接口")
@RestController
@RequestMapping("/records")
public class RecordsController {
    @Autowired
    private RecordsService recordsService;



    @ResponseBody
    @RequestMapping(value = "/check.json", method = RequestMethod.POST)
    @ApiOperation(
            value = "check",
            notes = "check ",
            httpMethod = "POST",
            produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParam(name = "jsonData", value = "{bookId:'1',openId:'1'}", dataType = "String", paramType = "body")
    public void check(HttpServletResponse response,  @RequestBody String jsonData) {
        JSONObject result=recordsService.check(jsonData);
        if (null != result) {
            ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjHourRespond(result));
        } else {
            ResponseUtils.putJsonResponse(response, BaseUtils.errorrRespond("查找失败"));
        }
    }
    @ResponseBody
    @RequestMapping(value = "/update.json", method = RequestMethod.POST)
    @ApiOperation(
            value = "update",
            notes = "update ",
            httpMethod = "POST",
            produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParam(name = "jsonData", value = "{bookId:'1',openId:'1',index:'3'}", dataType = "String", paramType = "body")
    public void update(HttpServletResponse response,  @RequestBody String jsonData) {
        String result=recordsService.update(jsonData);
        if (null != result) {
            ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjRespond(result));
        } else {
            ResponseUtils.putJsonResponse(response, BaseUtils.errorrRespond("查找失败"));
        }
    }

}

